<template>
	<div>
		<div class="form-box">
			<AplidForm :disabled="isDetail" ref="formEl" v-bind="formConfig" v-model="formModel" @reset="onReset" @submit="onSubmit">
				<template v-slot:amountForm>
					<div class="flex align-center w-100">
						<p class="money-label">
							<span>总金额</span>
							<span class="text-tag">¥{{ formModel.amass }}</span>
						</p>
						<p class="money-label">
							<span>大写</span>
							<span class="text-tag">{{ dealBigMoney(formModel.amass) }}</span>
						</p>
					</div>
				</template>
			</AplidForm>
		</div>
		<TablePart :headId="nowRowData.id"></TablePart>
	</div>
</template>

<script setup lang="ts">
import { dealBigMoney } from '@/utils/util'
import apiMod from '@/apiMod/index'
import TablePart from '../tablePart/index.vue'

const props = defineProps<{
	nowRowData: any
	isDetail?: boolean
}>()

const emit = defineEmits(['refresh'])
const formModel = ref({
	grantStatus: 0,
	...props.nowRowData,
})

const formConfig = {
	inline: false,
	showBtn: false,
	submitBtnText: '确定',
	backBtnText: '取消',
	labelPosition: 'top',
	labelWidth: '100px',
	column: [
		{
			label: '补贴金额',
			prop: 'amount',
			span: 24,
		},
	],
}

const onSubmit = (form, done) => {
	console.log(45, form)
	const tableRel = props.nowRowData.tableRel
	let formResultId
	if (tableRel) {
		const relData = JSON.parse(tableRel)
		formResultId = relData[0].result
	}
	apiMod
		.view_ofsSubsidyApply_receipt({
			...form,
			receiptStatusList: undefined,
			formResultId,
			year: props.nowRowData.belongYear,
			creditCode: props.nowRowData.creditCode,
			idList: props.nowRowData.ids.split(',') || [props.nowRowData.id],
			orgName: props.nowRowData.orgName,
		})
		.then(() => {
			ElMessage.success('操作成功')
			onReset()
			done()
		})
		.catch(() => {
			done()
		})
}

const onReset = () => {
	emit('refresh')
}
</script>

<style scoped lang="scss">
:deep(.el-form--default.el-form--label-top .el-form-item .el-form-item__label) {
	font-family: 'Microsoft YaHei Bold';
	font-weight: 700;
	font-size: 20px;
	text-align: left;
	color: #1c1c28;
}
.form-box {
	width: 60%;
	margin: 0 auto;
	.money-label {
		min-width: vw(200);
	}
	.text-tag {
		margin-left: 20px;
		padding: 4px 16px;
		height: 29px;
		border-radius: 6px;
		background: #f57350;
		font-family: 'Microsoft YaHei';
		font-weight: 400;
		font-size: 16px;
		text-align: left;
		color: #fff;
	}
}
</style>
